<?php
include_once("../modules/checkA.php");
include_once("../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'order'");

?>


<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];


//同意加上and，然后去除左边的and就可以了。
if($_REQUEST['select_keywords'])
{
    $keywords=" and (user_name like '%".$_REQUEST['select_keywords']."%' or remark like '%".$_REQUEST['select_keywords']."%'  or user_id like '%".$_REQUEST['select_keywords']."%' )";
}
else
{
    $keywords="";
}






if($_REQUEST['select_startday'])
{
    $start_date=$_REQUEST['select_startday'];
    $start_date_str=" and order_date >= '".$start_date."'";
}
else
{
    $start_date_str="";

}



if($_REQUEST['select_endday'])
{
    $end_date=$_REQUEST['select_endday'];
    $end_date_str=" and order_date <= '".$end_date."'";
}
else
{
    $end_date_str="";
}




if($_REQUEST['today'])
{
    $start_date=date("Y-m-d");
    $start_date_str=" and order_date >= '".$start_date."'";

    $end_date=date("Y-m-d");
    $end_date_str=" and order_date <= '".$end_date."'";
}




$select_str=$keywords.$start_date_str.$end_date_str;

$sort = "order_date desc , user_id asc , order_at asc";


$orderlist=select_lines_all_items($table_Prefix."orderlist",$sort,"nid >0 and (status != '取消' or status is null) ".$select_str,"");



$total_order = count($orderlist);



$userlist   = transform_2darray_in_1darray_number_as_key($orderlist, "user_name");
$userlist2  = array_flip(array_flip($userlist));
$total_user = count($userlist2); //这样便可以删除重复元素。);

$usermid= transform_2darray_in_1darray_with_new_key($orderlist,"user_name","user_id");




$user_meal= transform_2darray_in_1darray_with_new_key($orderlist,"user_name","order_at");




$total_zaocan = count_value_with_key_in_2d_array($orderlist, "order_at", "1");
$total_wucan  = count_value_with_key_in_2d_array($orderlist, "order_at", "2");



$parameter['target']="product_price";//需要统计的值
$parameter['data']=$orderlist;//需要统计

$total_price=count_value_in_2array_by_keys($parameter);



$meal['1']="早餐";
$meal['2']="午餐";
$meal['3']="晚餐";



?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include_once(ROOT_PATH_.'/controlbase/modules/head.php'); ?>
</head>

<body>

<div id="topbar"><?php include ROOT_PATH_.'/controlbase/modules/topbar.php'; ?></div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controlbase/modules/sidebar.php'; ?>
        </div>


<div id="content" class="layui-form">
<h1> 订单汇总 </h1>







    <div class="select-box layui-form">
        <form action="collect.php" >

            <div class="layui-form-item">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-block">
                    <input type="text" name="select_keywords" placeholder="可搜索姓名，备注，工号" autocomplete="off" class="layui-input" value="<? echo $_REQUEST['select_keywords']?>" >
                </div>
            </div>











            <div class="layui-form-item">
                <label class="layui-form-label">时间</label>

                <div class="layui-input-block">
                    <input type="text" name="select_startday" placeholder="请输入开始时间" autocomplete="off" class="layui-input"  onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" style="float: left; width: 112px" value="<?if($_REQUEST['select_startday']){echo $_REQUEST['select_startday'] ;} ?>" >

                    <span style="float: left;margin: 0 4px; line-height: 30px;">-</span>


                    <input type="text" name="select_endday" placeholder="请输入结束时间" autocomplete="off" class="layui-input" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  style="float: left; width:112px" value="<?if($_REQUEST['select_endday']){echo $_REQUEST['select_endday'] ;} ?>"  >


                    <input type="hidden" name="nav-itemed"  value="order" >


                </div>


            </div>


            <br class="clearfloat"/>


            <button class="layui-btn">查找</button>

            <a href="collect.php?nav-itemed=order&today=yes" class="layui-btn" lay-submit lay-filter="formMemberAdd" >清除</a>



            <br class="clearfloat"/>
        </form>

        <br class="clearfloat"/>
    </div>





<!-- 用$system_part .list_boxes来控制来到确认板块信息显示-->
<div class="list-box">


<div class="list-boxes">





<div>
    <table class="layui-table">

        <thead>
        <tr>
            <th>订餐的人数</th>
            <th>订单数量</th>
            <th>早餐数</th>
            <th>午餐数</th>
            <th>总价</th>
        </tr>
        </thead>


        <tbody>
        <tr>
            <td><?echo $total_user?></td>
            <td><?echo $total_order?></td>
            <td><?echo $total_zaocan?></td>
            <td><?echo $total_wucan?></td>
            <td><?echo $total_price?></td>
        </tr>
</tbody>
</table>





</div>













<table class="layui-table">
  <colgroup>
    <col width="60">
    <col width="100">
	<col >
	<col >
	<col >
	<col >
	<col >
	<col >
	<col >


    <col>
  </colgroup>
  <thead>
    <tr>
        <th>序号</th>
        <th>姓名</th>
        <th>工号</th>
        <th>早餐数</th>
        <th>早餐总金额</th>
        <th>午餐数</th>
        <th>午餐总金额</th>
        <th>总餐数</th>
        <th>总金额</th>
    </tr>
  </thead>
  <tbody>



  <?php
  if (count($userlist2) == 0)
  {
      echo "<tr><td colspan='8'>暂无数据</td></tr>";
  }
  ?>




	<?php
    $i=1;
    foreach($userlist2 as $k=>$val)
    {


        ?>

      <tr id="item<?echo $val['nid']?>" >
          <td><? echo $i++ ?></td>
          <td><? echo $val ?></td>
          <td><? echo $usermid[$val]?></td>
          <td><? echo $num_at_1=count_with_2_key_in_2d_array($orderlist,"user_name",$val,"order_at","1")?></td>

          <?
          $parameter['target'] = "product_price";//需要统计的值
          $parameter['data']   = $orderlist;//需要统计
          $parameter['key1']   = "user_name";//需要统计
          $parameter['value1']   = $val;//需要统计
          $parameter['key2']   = "order_at";//需要统计
          $parameter['value2']   = "1";//需要统计
          ?>
          <td><? echo $user_zaocan_price=count_value_in_2array_by_keys($parameter);?></td>
          <td><? echo $num_at_2=count_with_2_key_in_2d_array($orderlist,"user_name",$val,"order_at","2")?></td>
          <?$parameter['value2']   = "2";//需要统计?>
          <td><? echo $user_wucan_price=count_value_in_2array_by_keys($parameter);?></td>
          <td><? echo  $num_at_1+$num_at_2 ?></td>

          <? $parameter['key2']   = ""; ?>
          <td><? echo $user_can_price=count_value_in_2array_by_keys($parameter);?></td>
      </tr>



  <?php

}
?>


  </tbody>
</table>






</div>




</div>


<!--list-box end-->
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>







<!--删除box-->
<?php include '../modules/deletebar.php'; ?>
<!--删除box end-->

<?php include_once('../modules/footer.php'); ?> </body>
</html>
